﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HROReporting.Model.SchoolLocaties;
using HROReporting.Infrastructure.UnitOfWork;
using NHibernate;
using NHibernate.Criterion;
using HROReporting.Infrastructure.Querying;

namespace HROReporting.Repository.NHibernate.Repositories
{
    public class SchoolLocatieRepository : Repository<SchoolLocatie, int>, ISchoolLocatieRepository
    {
        public SchoolLocatieRepository(IUnitOfWork uow)
            : base(uow)
        {
        }

        public SchoolLocatie GetSchoolLocatieByLocatie(string locatie)
        {
            ICriteria criteriaQuery = SessionFactory.GetCurrentSession()
                .CreateCriteria(typeof(SchoolLocatie))
                .Add(Expression.Eq(PropertyNameHelper
                .ResolvePropertyName<SchoolLocatie>
                (s => s.Locatie), locatie));

            IList<SchoolLocatie> schoolLocaties = criteriaQuery.List<SchoolLocatie>();
            SchoolLocatie schoolLocatie = schoolLocaties.FirstOrDefault();

            return schoolLocatie;
        }
    }
}
